package com.ruoyi.base.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.base.domain.BaseFlowIo;
import com.ruoyi.base.service.IBaseFlowIoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 出入库Controller
 * 
 * @author yepanpan
 * @date 2025-04-15
 */
@RestController
@RequestMapping("/base/flowIo")
public class BaseFlowIoController extends BaseController
{
    @Autowired
    private IBaseFlowIoService baseFlowIoService;

    /**
     * 查询出入库列表
     */
    @PreAuthorize("@ss.hasPermi('base:flowIo:list')")
    @GetMapping("/list")
    public TableDataInfo list(BaseFlowIo baseFlowIo)
    {
        startPage();
        List<BaseFlowIo> list = baseFlowIoService.selectBaseFlowIoList(baseFlowIo);
        return getDataTable(list);
    }

    /**
     * 导出出入库列表
     */
    @PreAuthorize("@ss.hasPermi('base:flowIo:export')")
    @Log(title = "出入库", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BaseFlowIo baseFlowIo)
    {
        List<BaseFlowIo> list = baseFlowIoService.selectBaseFlowIoList(baseFlowIo);
        ExcelUtil<BaseFlowIo> util = new ExcelUtil<BaseFlowIo>(BaseFlowIo.class);
        util.exportExcel(response, list, "出入库数据");
    }


    /**
     * 获取出入库详细信息
     */
    @PreAuthorize("@ss.hasPermi('base:flowIo:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(baseFlowIoService.selectBaseFlowIoById(id));
    }

    /**
     * 新增出入库
     */
    @PreAuthorize("@ss.hasPermi('base:flowIo:add')")
    @Log(title = "出入库", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody BaseFlowIo baseFlowIo)
    {
        return toAjax(baseFlowIoService.insertBaseFlowIo(baseFlowIo));
    }

    /**
     * 修改出入库
     */
    @PreAuthorize("@ss.hasPermi('base:flowIo:edit')")
    @Log(title = "出入库", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody BaseFlowIo baseFlowIo)
    {
        baseFlowIo.setUpdateBy(getUsername());
        return toAjax(baseFlowIoService.updateBaseFlowIo(baseFlowIo));
    }

    /**
     * 删除出入库
     */
    @PreAuthorize("@ss.hasPermi('base:flowIo:remove')")
    @Log(title = "出入库", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(baseFlowIoService.deleteBaseFlowIoByIds(ids));
    }
}
